const {
    desktopCapturer,
    ipcMain,
    nativeImage
} = require('electron')

const handleDesktopCapturer = () => {
    ipcMain.handle("getAllWindowsHwnd", async (event, data) => {
        try {
            const sources = await desktopCapturer.getSources({
                types: ['window', 'screen']
            });
            
            return sources.map(source => ({
                id: source.id,
                name: source.name,
                thumbnail: source.thumbnail.toDataURL()
            }));
        } catch (error) {
            return [];
        }
    });
}

module.exports = {
    handleDesktopCapturer
}